#include <iostream>
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

class Util
{
public:
    static bool Readfile(const std::string& path, std::string* fileContent)
    {
        struct stat st;
        int n = stat(path.c_str(), &st);
        if (n < 0) return false;
        int size = st.st_size;

        fileContent->resize(size);

        int fd = open(path.c_str(), O_RDONLY);
        if (fd < 0) return false;
        read(fd, (char*)fileContent->c_str(), size);
        close(fd);
        return true;
    }

    static std::string ReadOneLine(std::string& message, const std::string& sep)
    {
        auto pos = message.find(sep);
        if (pos == std::string::npos) return "";
        std::string s = message.substr(0, pos);
        message.erase(0, pos+sep.size());
        return s;
    }

    static bool ParseRequestLine(const std::string& line, std::string* method, std::string* url, std::string* httpVersion)
    {
        std::stringstream ss(line);
        ss >> *method >> *url >> *httpVersion;
        return true;
    }
};